﻿CREATE PROCEDURE [dbo].[ArticleAttributes_UpdateFromTempArticleAttributes]
	@RangeReviewId int = 1
AS


--Limpio la segmentacion anterior.
delete from ArticleAttributes where ArticleId in (select Id from Articles where RangeReviewId = @RangeReviewId)

--Inserto la nueva segementacion.
insert into ArticleAttributes (ArticleId, AttributeId)
select distinct a.Id, t.AttributeId
from TempArticleAttributes t
inner join Articles a on a.Code = t.Code and a.UOM = t.UOM
where a.RangeReviewId = @RangeReviewId
